package git.soulbgm.mapreduce.compress;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author SoulBGM
 * @date 2021/11/17 23:55
 */
public class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> {

    private Text outKey = new Text();
    private IntWritable outValue = new IntWritable(1);

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();

        // 按一个或多个空格分隔字符
        String[] split = line.split("\\s+");

        for (String s : split) {
            outKey.set(s);
            context.write(outKey, outValue);
        }
    }
}
